﻿@using GlobalResources
@using Microsoft.Azure.Devices.Applications.RemoteMonitoring.Common.Models.Commands
@model Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.Models.CommandModel

@using (Ajax.BeginForm("SendCommand", "DeviceCommand", null,
        new AjaxOptions()
        {
            HttpMethod = "POST",
            OnBegin = "IoTApp.DeviceCommand.onBegin",
            OnFailure = "IoTApp.DeviceCommand.onFailure",
            OnSuccess = "IoTApp.DeviceCommand.onSuccess",
            OnComplete = "IoTApp.DeviceCommand.onComplete",
            LoadingElementId = "loadingElement",

        }, null))
{
    @Html.AntiForgeryToken()
    <p class="command_description">@Model.Description</p>
    for (var i = 0; i < Model.Parameters.Count; i++)
    {
        <div class="command_parameter_field">
            @Html.LabelFor(m => m.Parameters[i].Name, Model.Parameters[i].Name, new { @class = "command_parameter_field__label" })
            @Html.EditorFor(m => m.Parameters[i].Value, string.Format("edit_{0}", Model.Parameters[i].Type), new { Suffix = string.Format("Value_{0}", i) })
            @Html.ValidationMessageFor(m => m.Parameters[i].Value)
            @foreach (var message in Model.Parameters[i].ErrorMessages)
            {
                @IoTHelpers.ErrorLabel(message);
            }
            @Html.HiddenFor(model => Model.Parameters[i].Name)
            @Html.HiddenFor(model => Model.Parameters[i].Type)
        </div>

    }

    @Html.HiddenFor(command => command.Name)
    @Html.HiddenFor(command => command.DeviceId)
    @Html.HiddenFor(command => command.DeliveryType)
    <button type="submit" id="sendCommand_button" class="button_base button_execute">@Strings.SendCommand</button>
}